package serveur;

import java.io.IOException;
import java.net.ServerSocket;
import java.net.Socket;

import org.apache.log4j.Logger;
import org.apache.log4j.PropertyConfigurator;

/**
 * Serveur version multithread, qui instancie un certains nombre de threads qui attendent la connexion
 * des clients pour repondre a leurs requetes (1 thread = 1 client/requete)
 * 
 * @author Erik
 */
public class ServeurPool {

	private static final int NBTHREADS = 100;
	private static final int ITERATIONS = 5;

	private final static Logger logger = Logger.getLogger(ServeurMulithread.class);
	private static ServerSocket serveurSocket;

	public static void main(String[] args) {
		try {
			PropertyConfigurator.configure("log4j.properties");

			serveurSocket = new ServerSocket(2009);
			logger.info("Lancement du serveur sur le port 2009");
			System.out.println("Serveur lance sur le port: 2009, en attente de connexion d'un client");

			Thread threadDialogue[] = new Thread[NBTHREADS];
			for (int j = 0; j < NBTHREADS; j++) {
				threadDialogue[j] = new Thread(new ThreadDialogue2(j, serveurSocket));
			}
			for (int j = 0; j < NBTHREADS; j++) {
				threadDialogue[j].start();
			}

		} catch (IOException e) {
			e.printStackTrace();
		}

	}
}
